Skip to content

[FEAT] Allow building octree with particles#5435

Open
cphyc wants to merge 4 commits into
yt-project:mainfrom
cphyc:octree-particles
Open

[FEAT] Allow building octree with particles#5435
cphyc wants to merge 4 commits into
yt-project:mainfrom
cphyc:octree-particles

Conversation

@cphyc
Copy link
Copy Markdown
Member

@cphyc cphyc commented Apr 21, 2026

PR Summary

Allow building an octree with the stream dataset type that handles particles.

import yt

import numpy as np

L = [-1, -1, -1]
R = [1, 1, 1]
oct_mask = np.zeros(33) # 5 refined values gives 7 * 4 + 5 octs to mask
oct_mask[[0,  5,  7, 16]] = 8
octree_mask = np.array(oct_mask, dtype=np.uint8)
quantities = {}
rng = np.random.default_rng(12345)
quantities["gas", "density"] = lambda: rng.random((29, 1))
quantities["gas", "dinos"] = (lambda: rng.random((29, 1)), "Msun")

quantities["io", "particle_position_x"] = (rng.uniform(L[0], R[0], size=100), "code_length")
quantities["io", "particle_position_y"] = (rng.uniform(L[1], R[1], size=100), "code_length")
quantities["io", "particle_position_z"] = (rng.uniform(L[2], R[2], size=100), "code_length")
quantities["io", "particle_mass"] = (rng.random(100), "Msun")
bbox = np.array([L, R]).T

ds = yt.load_octree(
    octree_mask=octree_mask,
    data=quantities,
    bbox=bbox,
    num_zones=1,
    partial_coverage=0,
)

p = yt.ProjectionPlot(ds, "x", ("gas", "density"))
p.annotate_particles(100, ptype="io")
p.save()

Produces (as it should!):

OctreeData_Projection_x_density

PR Checklist

  • New features are documented, with docstrings and narrative docs
  • Adds a test for any bugs fixed. Adds tests for new features.

I've also added an explicit test for the feature introduced in #5338.

@cphyc cphyc force-pushed the octree-particles branch from e47c24f to d55cddb Compare April 21, 2026 16:29
@cphyc cphyc force-pushed the octree-particles branch from d55cddb to d6c370e Compare April 21, 2026 16:47
matthewturk
matthewturk previously approved these changes Apr 21, 2026
Copy link
Copy Markdown
Member

@matthewturk matthewturk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I see it in here, but does this need to build the octree with the octree machinery that exposes nref, etc?

@matthewturk matthewturk dismissed their stale review April 21, 2026 17:20

oops didn't mean to approve yet

@cphyc
Copy link
Copy Markdown
Member Author

cphyc commented Apr 22, 2026

If I understand your comment properly, your asking about reusing the machinery for indexing SPH datasets? Anyway, here, I simply use the select_points function with no additional indexing to reject particles.
Performances will be poor and parallelism inexistent, and there's no chunking but it allows building in-memory datasets that combine octree data with particles.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants